<?php
	echo $this->Html->css('/lil_media/css/lil_media');
?>
<div class="index" id="MediaIndex">
<?php
	foreach ($data as $item) {
		$path_parts = pathinfo($base_path . DS . $item['filename']);
		
		echo '<div class="media_item">';
		
		$icon = '';
		if (in_array($path_parts['extension'], array('gif', 'png', 'jpg'))) {
			$icon = $this->Html->image($www_dir . $path_parts['basename']);
		} else if (in_array($path_parts['extension'], array('doc', 'docx'))) {
			$icon = $this->Html->image('doc.gif');
		} else if (in_array($path_parts['extension'], array('xls', 'xlsx'))) {
			$icon = $this->Html->image('xls.gif');
		} else if ($path_parts['extension'] == 'pdf') {
			$icon = $this->Html->image('pfd.gif');
		} else {
			$icon = $this->Html->image('x.gif');
		}
		
		echo $this->Html->link(
			$icon,
			array(
				'action'   => 'view',
				'path'     => (!empty($this->params['named']['path'])) ?
					$this->params['named']['path'] : null,
				'filename' => $path_parts['basename']
			),
			array(
				'escape' => false,
				'onclick' => '
					window.opener.CKEDITOR.tools.callFunction( ' . @$this->params['url']['CKEditorFuncNum']. ', \'' . 
					Dispatcher::baseUrl() . $www_dir . $path_parts['basename'] .
					'\' ); window.close();'
			)
		);
		
		echo '<div class="media_name">';
		echo $this->Html->link(
			$path_parts['basename'],
			array(
				'action' => 'view',
				'path'   => (!empty($this->params['named']['path'])) ?
					$this->params['named']['path'] : null,
				'filename'   => $path_parts['basename']
			),
			array(
				'onclick' =>
					'window.opener.CKEDITOR.tools.callFunction( ' . @$this->params['url']['CKEditorFuncNum']. ', \'' . 
					Dispatcher::baseUrl() . $www_dir . $path_parts['basename'] .
					'\' ); window.close();'
			)
		);
		echo '</div>';
		echo '</div>';
	}
?>
	<div style="width: 100%">&nbsp;</div>
</div>